package com.ljh.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author: Themberfue
 * @date: 2025/3/25 19:30
 * @description:
 */
@Slf4j
@Aspect
@Component
@Order(2)
public class AspectDemo4 {
    @Pointcut("execution(* com.ljh.aop.controller.*.*(..))")
    public void pt() {}

    @Around("pt()")
    public Object aspectDemo(ProceedingJoinPoint pjp) {
        // TODO 执行目标方法之前执行
        log.info("demo4：目标方法执行前...");
        Object res;
        try {
            // TODO 执行目标方法
            res = pjp.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
        // TODO 执行目标方法之后执行
        log.info("demo4：目标方法执行后...");
        return res;
    }
}
